//
//  YLPickerView.m
//  yuLink
//
//  Created by 孙强 on 2021/2/16.
//

#import "YLPickerView.h"

@implementation YLPickerView

+ (void)showPickViewWithHeight:(CGFloat)height selectDate:(NSDate *)selectDate pickerModel:(BRDatePickerMode)pickerModel callback:(void (^)(NSDate * _Nonnull, NSString * _Nonnull))clickBlock {
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc] init];
    datePickerView.pickerMode = pickerModel;
    datePickerView.maxDate = [NSDate date];
    datePickerView.showUnitType = BRShowUnitTypeAll;
    if (selectDate) {
        datePickerView.selectDate = selectDate;
    }
    datePickerView.pickerStyle = [self pickerStyleWithHeight:height];
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        if (clickBlock) {
            clickBlock(selectDate, selectValue);
        }
    };
    [datePickerView show];
}

+ (void)showPickViewWithHeight:(CGFloat)height selectDate:(NSDate *)selectDate minDate:(NSDate *)minDate maxDate:(NSDate *)maxdate pickerModel:(BRDatePickerMode)pickerModel callback:(void(^)(NSDate *date, NSString *str))clickBlock {
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc] init];
    datePickerView.pickerMode = pickerModel;
    datePickerView.minDate = minDate;
    datePickerView.maxDate = maxdate;
    datePickerView.showUnitType = BRShowUnitTypeAll;
    if (selectDate) {
        datePickerView.selectDate = selectDate;
    }
    datePickerView.pickerStyle = [self pickerStyleWithHeight:height];
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        if (clickBlock) {
            clickBlock(selectDate, selectValue);
        }
    };
    [datePickerView show];
}

+ (void)showStringPickViewWithHeight:(CGFloat)height selectIdx:(NSInteger)selectIdx dataSourceArr:(NSArray *)dataSourceArr callback:(void(^)(BRResultModel *resultModel))clickBlock {
    BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
    stringPickerView.pickerMode = BRStringPickerComponentSingle;
    stringPickerView.dataSourceArr = dataSourceArr;
    stringPickerView.selectIndex = selectIdx;
    stringPickerView.pickerStyle = [self pickerStyleWithHeight:height];
    stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        if (clickBlock) {
            clickBlock(resultModel);
        }
    };
    [stringPickerView show];
}

+ (void)showStringPickViewWithHeight:(CGFloat)height selectIdx:(NSInteger)selectIdx dataSourceArr:(NSArray *)dataSourceArr title:(NSString *)title callback:(void(^)(BRResultModel *resultModel))clickBlock {
    BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
    stringPickerView.pickerMode = BRStringPickerComponentSingle;
    stringPickerView.dataSourceArr = dataSourceArr;
    stringPickerView.selectIndex = selectIdx;
    stringPickerView.title = title;
//    stringPickerView.
    stringPickerView.pickerStyle = [self pickerStyleWithHeight:height];
    stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        if (clickBlock) {
            clickBlock(resultModel);
        }
    };
    [stringPickerView show];
}

+ (BRPickerStyle *)pickerStyleWithHeight:(CGFloat)height {
    BRPickerStyle *customStyle = [[BRPickerStyle alloc] init];
    customStyle.cancelBtnTitle = REAPPString(@"取消");
    customStyle.cancelTextColor = lightTitleColor;
    customStyle.doneTextColor = COLOR_MAIN;
    customStyle.doneBtnTitle = REAPPString(@"确定");
    customStyle.rowHeight = 50;
    customStyle.topCornerRadius = 15;
    customStyle.pickerHeight = height;
    customStyle.pickerTextFont = [UIFont systemFontOfSize:15];
    customStyle.dateUnitTextColor = UIColor.redColor;
    customStyle.pickerTextColor = colorFromHexStringWithAlpha(@"171A1D", 0.6);
    customStyle.separatorColor = COLOR_Line_BG;
    customStyle.titleTextFont = [UIFont boldSystemFontOfSize:18];
    customStyle.titleTextColor = MainTitleColor;
    customStyle.selectRowColor = colorFromHexStringWithAlpha(@"EAEBED", 1);

    return customStyle;
}

@end
